public class demo15 {
    public static void main(String[] args) {
        final int count = 9;
        int buy = 1;//实际购买的瓶数
        while (true) {
            //空瓶子的数量必定和买的瓶数相同
            int empty = buy;
            int bottle = buy;
            //只要空瓶子超过2个，则可以换购
            while (empty >= 3) {
                bottle += empty / 3;
                empty = empty / 3 + empty % 3;
            }

            if (bottle >= count) {//买的瓶数+换购的瓶数超过9，则说明够9个人喝
                System.out.println("买" + buy + "瓶，可以够" + bottle + "人喝,剩下空瓶子：" + empty);
                break;
            }
            buy++; //不足9人喝，则继续购买
        }
    }
}
